#
from config import HOST


class ApiRegisterLogin:
    def __init__(self,session):
        self.session=session
        self.__url_img_code=HOST+"/common/public/verifycode1/{}"
        self.__url_phone_code=HOST+"/member/public/sendSms"
        self.__url_register=HOST+"/member/public/reg"
        self.__url_login=HOST+"/member/public/login"
        self.__url_query_login_status=HOST+"/member/public/islogin"
    def api_img_code(self,r):
        return self.session.get(url=self.__url_img_code.format(r))
    def api_phone_code(self,phone,imgVerifyCode):
        data={
            "phone":phone,
            "imgVerifyCode":imgVerifyCode,
            "type":"reg"
        }
        return self.session.post(url=self.__url_phone_code,data=data)
    def api_register(self,phone,password,verifycode,phone_code):
        data = {
            "phone": phone,
            "password": password,
            "verifycode": verifycode,
            "phone_code":phone_code,
            "dy_server":"on",
            "invite_phone":""
        }
        return self.session.post(url=self.__url_register, data=data)
    def api_login(self,keywords,password):
        data = {
            "keywords": keywords,
            "password": password
        }
        return self.session.post(url=self.__url_login, data=data)
    def api_query_login_status(self):
        return self.session.post(url=self.__url_query_login_status)